const { DataTypes } = require('sequelize');

// const sequelize = require("@/db/seq");
const sequelize = require("@/db/seq");
const User_Roles = sequelize.define("user_roles", {
  user_id: {
    type: DataTypes.INTEGER,
    references: { 
      model: 'blog_users',
      key: 'id'
    },
    onDelete: 'CASCADE'
  },
  role_id: {
    type: DataTypes.INTEGER,
    references: {
      model: 'blog_roles',
      key: 'id'
    },
    onDelete: 'CASCADE'
  },
})
User_Roles.associate = (models) => {
  User_Roles.belongsTo(models.blog_user, {
    foreignKey: 'user_id',
    as: 'user'
  });
  User_Roles.belongsTo(models.blog_roles, {
    foreignKey: 'role_id',
    as: 'role'
  });
}
// User_Roles.sync({ force: false, alter: true });
module.exports = User_Roles;
